package com.upsuns.service;

import java.io.IOException;
import java.rmi.AlreadyBoundException;
import java.rmi.NotBoundException;
import java.util.Scanner;

import com.upsuns.client.Client;
import com.upsuns.server.Server;

/**
 *@Description:<p>程序起始入口</p>
 *@author 王旭
 *@time 2016年3月14日 下午11:36:35
 */
public class Lancher {
	
	public static Scanner scan = new Scanner(System.in);
	
	public static void main(String[] args) throws IOException, AlreadyBoundException, NotBoundException {
		
		System.out.println("1--------发送文件");
		System.out.println("2--------接收文件");
		
		int menu1 = scan.nextInt();
		if(menu1 == 1) {
			serverMain();
		}
		else if(menu1 == 2){
			clientMain();
		}
		else {
			System.out.println("输入有误");
		}
		
	}
	
	public static void serverMain() throws IOException, AlreadyBoundException {
		System.out.println("输入要传输的文件路径：");
		String path = scan.next();
		Server server = new Server(path);
		server.doServer();
	}
	
	public static void clientMain() throws NotBoundException, IOException {
		Client client = new Client();
		System.out.println("输入要接收文件的来源地址：");
		String host = scan.next();
		client.bind(host);
		System.out.println("输入文件要保存的路径：");
		String path = scan.next();
		client.setSavePath(path);
		client.doClient();
	}

}
